翻訳と辞書
Words near each other
・ Compassionate Sex
・ Compasso d'Oro
・ Compassvale
・ Compassvale LRT Station
・ Compat.egov
・ Compathia
・ Compati Hero Series
・ Compatibilism
・ Compatibility
・ Compatibility (chemical)
・ Compatibility (geochemistry)
・ Compatibility (mechanics)
・ Compatibility card
・ Compatibility layer
・ Compatibility mode
Compatibility of C and C++
・ Compatibility testing
・ Compatibilization
・ Compatible Discrete 4
・ Compatible ink
・ Compatible Partners
・ Compatible sideband transmission
・ Compatible system of ℓ-adic representations
・ Compatible Time-Sharing System
・ Compatil
・ Compatriot
・ Compatriot Party
・ Compatriots Club
・ Compay Segundo
・ Compañero y Compañera


Dictionary Lists
翻訳と辞書 辞書検索 [ 開発暫定版 ]
スポンサード リンク

Compatibility of C and C++ : ウィキペディア英語版
Compatibility of C and C++

The C and C++ programming languages are closely related. C++ grew out of C, as it was designed to be source-and-link compatible with C. Due to this, development tools for the two languages (such as IDEs and compilers) are often integrated into a single product, with the programmer able to specify C or C++ as their source language. However, due to minor semantic differences, most non-trivial C programs will not compile as C++ code without modification — C++ is not a superset of C.〔(【引用サイトリンク】title=Bjarne Stroustrup's FAQ – Is C a subset of C++? )
Likewise, C++ introduces many features that are not available in C and in practice almost all code written in C++ is not conforming C code. This article, however, focuses on differences that cause conforming C code to be ill-formed C++ code, or to be conforming/well-formed in both languages, but to behave differently in C and C++.
Bjarne Stroustrup, the creator of C++, has suggested that the incompatibilities between C and C++ should be reduced as much as possible in order to maximize inter-operability between the two languages. Others have argued that since C and C++ are two different languages, compatibility between them is useful but not vital; according to this camp, efforts to reduce incompatibility should not hinder attempts to improve each language in isolation. The official rationale for the 1999 C standard (C99) "endorse() the principle of maintaining the largest common subset" between C and C++ "while maintaining a distinction between them and allowing them to evolve separately", and stated that the authors were "content to let C++ be the big and ambitious language."〔(Rationale for International Standard—Programming Languages—C ), revision 5.10 (April 2003).〕
Several additions of C99 are or were not supported in C++ or conflicted with C++ features, such as variadic macros, compound literals, designated initializers, variable-length arrays, and native complex number types. The long long int datatype and restrict type qualifier defined in C99 were not included in the C++03 standard, but most mainstream compilers such as the GNU Compiler Collection,〔(Restricted Pointers ) from ''Using the GNU Compiler Collection (GCC)''〕 Microsoft Visual C++, and Intel C++ Compiler provided them as an extension. The long long datatype along with variadic macros are present in the new C++ standard, C++11. On the other hand, C99 has reduced some other incompatibilities by incorporating C++ features such as // comments and mixed declarations and code.〔(【引用サイトリンク】title=C Dialect Options - Using the GNU Compiler Collection (GCC) )
==Constructs valid in C but not in C++==

* One commonly encountered difference is C being more weakly-typed regarding pointers. For example, C allows a void
*
pointer to be assigned to any pointer type without a cast, while C++ doesn't; this idiom appears often in C code using malloc memory allocation.〔(【引用サイトリンク】title=IBM Knowledge Center )〕 For example, the following is valid in C but not C++:
void
* ptr;
/
* Implicit conversion from void
* to int
*
*/
int
*i = ptr;

:or similarly:
int
*j = malloc(sizeof(int)
* 5); /
* Implicit conversion from void
* to int
*
*/
:In order to make the code compile in C++, one must use an explicit cast:

void
* ptr;
int
*i = static_cast*>(ptr);
int
*j = static_cast*>(malloc(sizeof(int)
* 5));

* C++ adds numerous additional keywords to support its new features. This renders C code using those keywords for identifiers invalid in C++. For example:

struct template
;

:is valid C code, but is rejected by a C++ compiler, since the keywords "template", "new" and "class" are reserved.
* C++ compilers prohibit using goto or switch from crossing an initialization, as in the following C99 code:

void fn(void)

* In C, struct, union, and enum types must be indicated as such whenever the type is referenced: in struct foo ; int bar(foo arg); is valid C++.
* Enumeration constants (enum values) are always of type int in C, whereas they are distinct types in C++ and may have a size different from that of int. C++11 allows the programmer to use custom integer types for the values of an enum.
* C++ changes some C standard library functions to add additional polymorphic functions with const type qualifiers, e.g. strchr returns char
*
in C, while C++ acts as if there were two polymorphic functions const char
*strchr(const char
*)
and a char
*strchr(char
*)
.
* In both C and C++, one can define nested struct types, but the scope is interpreted differently (in C++, a nested struct is defined only within the scope/namespace of the outer struct).
* Non-prototype ("K&R"-style) function declarations are not allowed in C++, although they have also been deprecated in C since 1990. Similarly, implicit function declarations (using functions that have not been declared) are not allowed in C++, but have also been deprecated in C since 1999.
* C allows struct, union, and enum types to be declared in function prototypes, whereas C++ does not.
* In C, a function prototype without parameters, e.g. int foo();, implies that the parameters are unspecified. Therefore, it is legal to call such a function with one or more arguments, e.g. foo(42, "hello world"). In contrast, in C++ a function prototype without arguments means that the function takes no arguments, and calling such a function with arguments is ill-formed. In C, the correct way to declare a function that takes no arguments is by using 'void', as in int foo(void);, which is also valid in C++.
* C++ is more strict than C about pointer assignments that discard a const qualifier (e.g. assigning a const int
*
value to an int
*
variable): in C++ this is invalid and generates a compiler error (unless an explicit typecast is used), whereas in C this is allowed (although many compilers emit a warning).
* In C++ a const variable must be initialized; in C this is not necessary.
* C99 and C11 added several features to C that have not been incorporated into standard C++, such as the _Complex type and designated initializers.

抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)
ウィキペディアで「Compatibility of C and C++」の詳細全文を読む



スポンサード リンク
翻訳と辞書 : 翻訳のためのインターネットリソース

Copyright(C) kotoba.ne.jp 1997-2016. All Rights Reserved.